"""
Calendar
========

`Calendar` has three oddities:

- Does not display properly when placed inside a `SizedPanel`.
- Has no event for when the day is changed (although there is one for
when a day cell is clicked)
- The event object does not have a reference to the widget itself

Nonetheless, `Calendar` is more accessible than `CalendarCtrl`, because the
user can TAB in and out of it.
"""
from wxpita import *
from wxpita.lib import *
import wx.lib.calendar

f = SizedFrame [
    Panel [
        Calendar(name='cal1', pos=(10, 10)),

        Calendar(name='cal2', pos=(220, 10)),    
    ],
    
    TextCtrl(name='log', style='te_multiline', expand=True, proportion=2),
]

def on_click_calendar(evt):
    mesg = 'Date changed to "%d-%d-%d"\n' % (evt.year, evt.month, evt.day)
    f.log.AppendText(mesg)

@f.Init
def _():
    f.cal1.SetYear(1902)
    f.cal1.SetMonth(9)
    f.cal1.SetDayValue(7)

    f.cal2.SetCurrentDay()
    f.cal2.AddSelect([4,8,9,14,22,28], 'WHITE', 'BLUE')

    f.cal1.Bind(wx.lib.calendar.EVT_CALENDAR, on_click_calendar)
    f.cal2.Bind(wx.lib.calendar.EVT_CALENDAR, on_click_calendar)

f.Show('Calendar Example', size=(500,500))
